package CGW.bean;

import java.util.ArrayList;
import java.util.List;

public class Page<T> {
    private List<T> datas;
    private int current;  // 当前页
    private int pages; // 总页数
    private int pageSize; // 每页显示的记录数
    private List<Integer> pageRange;  // 页码范围列表

    public Page() {
    }

    public Page(List<T> datas, int current, int pages, int pageSize) {
        this.datas = datas;
        this.current = current;
        this.pages = pages;
        this.pageSize = pageSize;

        pageRange = new ArrayList<>();
        int i = 1;
        while (i <= pages){
            pageRange.add(i);
            i ++;
        }
    }

    public boolean hasPrevious(){ // 是否存在上一页
        return current > 1;
    }

    public boolean hasNext(){ // 是否存在下一页
        return current < pages;
    }

    public int next(){  // 下一页的页码
        if(hasNext()) return current+1;
        return current;
    }

    public int previous(){ // 上一页的页码
        if(hasPrevious()) return current-1;
        return current;
    }

    public List<T> getDatas() {
        return datas;
    }

    public void setDatas(List<T> datas) {
        this.datas = datas;
    }

    public int getCurrent() {
        return current;
    }

    public void setCurrent(int current) {
        this.current = current;
    }

    public int getPages() {
        return pages;
    }

    public void setPages(int pages) {
        this.pages = pages;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public List<Integer> getPageRange() {
        return pageRange;
    }
}
